package action.chap6;

import action.chap4.Dish;
import action.chap4.DishUtils;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static java.util.stream.Collectors.*;

public class Demo632 {
    public static void main(String[] args) {
        List<Dish> menus = DishUtils.getListDish();
        Map<Dish.Type, Long> collect = menus.stream().collect(groupingBy(Dish::getType, counting()));
        Map<Dish.Type, Set<Demo63.CaloricLevel>> caloricLevelsByType =
                menus.stream().collect(
                        groupingBy(Dish::getType, mapping(
                                dish -> { if (dish.getCalories() <= 400) return Demo63.CaloricLevel.DIET;
                                else if (dish.getCalories() <= 700) return Demo63.CaloricLevel.NORMAL;
                                else return Demo63.CaloricLevel.FAT; },
                                toCollection(HashSet::new) )));
    }
}
